//
//  VisitorView.swift
//  WeiBo(Swift)
//
//  Created by 周成龙 on 16/9/21.
//  Copyright © 2016年 ZCL. All rights reserved.
//

import UIKit

class VisitorView: UIView {
    
    
    @IBOutlet weak var titleTextLabel: UILabel!
    @IBOutlet weak var rotationImageView: UIImageView!
    @IBOutlet weak var iconImageView: UIImageView!
    @IBOutlet weak var loginButton: UIButton!
    @IBOutlet weak var resignButton: UIButton!
    
    
    class func visitorView() -> VisitorView {
        return Bundle.main.loadNibNamed("VisitorView", owner: nil, options: nil)?.last as! VisitorView
    }
    
    func setupVisitorView(imageName: String?, title:String) {
        
        titleTextLabel.text = title
        guard let name = imageName else {
            starAnimation()
            return
        }
        rotationImageView.isHidden = true
        iconImageView.image = UIImage(named: name)
    }
    
    func starAnimation() {
        
        let anim = CABasicAnimation.init(keyPath: "transform.rotation")
        anim.toValue = M_PI * 2
        anim.repeatCount = MAXFLOAT
        anim.duration = 5.0
        anim.isRemovedOnCompletion = false
        rotationImageView.layer.add(anim, forKey: nil)
    }
}
